#include<vector>
#include<iostream>
using namespace std;


// 对于这个算法为什么行，我还是有疑问！！
// 查看这个图片
// https://leetcode.cn/problems/container-with-most-water/solutions/3804961/bian-li-bu-zou-by-sistwalkci-t7ek/
class Solution {
public:
    int maxArea(vector<int>& height) {
        int n = height.size();
        int i = 0, j = n - 1;

        int ans = 0, cur = 0;
        while(i < j) {
            cur = (j - i) * min(height[j], height[i]);
            // cout << cur << endl;
            ans = max(ans, cur);

            if (height[i] <= height[j]) i++;
            else j --;
        }

        return ans;
    }
};